<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/common.css" />
		<style type="text/css">
			ul.mui-table-view {
				margin-top: 20px;
			}
			
			ul.mui-table-view i.iconfont {
				margin-right: 12px;
				font-size: 20px;
			}
			
			ul.logout li {
				color: #FF3B30;
				text-align: center;
			}
			
			ul.logout li i.iconfont {
				font-weight: lighter;
				margin: 2px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">设置</h1>
		</header>

		<div class="mui-content">
			<ul class="mui-table-view mui-table-view-chevron">
				<li class="mui-table-view-cell check" id="account-and-security">
					<a class="mui-navigate-right">
						<i class="iconfont" style="color: #70BC46">&#xe617;</i>账号与安全
					</a>
				</li>
				<li class="mui-table-view-cell" id="universal-settings">
					<a class="mui-navigate-right">
						<i class="iconfont" style="color: #FF8040">&#xe616;</i>通用设置
					</a>
				</li>
			</ul>

			<ul class="mui-table-view mui-table-view-chevron">
				<li class="mui-table-view-cell" id="feedback">
					<a class="mui-navigate-right">
						<i class="iconfont" style="color: #EE9611">&#xe62c;</i>意见反馈
					</a>
				</li>
				<li class="mui-table-view-cell" id="aboutus">
					<a class="mui-navigate-right">
						<i class="iconfont" style="color: #F6047F;">&#xe652;</i>关于
					</a>
				</li>
				<li class="mui-table-view-cell update" id="update">
					<a class="mui-navigate-right">
						<i class="iconfont" style="color: #09C7F7">&#xe620;</i>检查更新
					</a>
				</li>
			</ul>

			<ul class="mui-table-view logout">
				<li class="mui-table-view-cell">
					<i class="iconfont">&#xe682;</i>注销账号
				</li>
			</ul>

		</div>
		<script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/common.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/user.js" type="text/javascript" charset="utf-8"></script>
		<script>
			mui.plusReady(function() {
				mui('.mui-table-view-chevron').on('tap', '.mui-table-view-cell', function() {
					if($(this).hasClass('check') && !User.islogin()) {
						Common.openWindow('login.html');
					} else {
						if(this.id == 'update' && plus.os.name == 'iOS') {
							mui.toast('当前系统为iOS');
						} else {
							Common.openWindow(this.id + '.html');
						}
					}
				})
				
				// 注销账号
				mui('.mui-table-view.logout').on('tap', '.mui-table-view-cell', function() {
					loginout();
				})
				
				// 修改密码成功后，退出登录
				document.addEventListener('back', function() {
					loginout();
				})
				
				function loginout() {
					var url = baseURL + "user/logout.json";
					Common.ajax({
						url : url
					}, function(data) {
						console.log(JSON.stringify(data));
						mui.toast("已注销");
						User.clearState();
						var indexPage = plus.webview.getLaunchWebview();
						var detailPage = plus.webview.currentWebview().opener();
						var artshowPage = indexPage.children()[2];
						var msgPage = indexPage.children()[3];
						mui.fire(detailPage, 'update', { logindata: 0 });
						mui.fire(msgPage, 'reload');
						mui.fire(indexPage, 'stateChange');
						mui.fire(artshowPage, 'stateChange');
						mui.back();
					}, function(xhr) {
						mui.toast('网络异常，请稍后再试');
						console.error('failed - ' + xhr.status + ' : ' + xhr.statusText);
					})
				}
			})
		</script>

	</body>

</html>